What is normalize.css?
The npm package normalize.css is a modern, HTML5-ready alternative to CSS resets. It makes browsers render all elements more consistently and in line with modern standards by precisely targeting only the styles that need normalizing.
What are normalize.css's main functionalities?
HTML Element Normalization
Ensures consistent line height and prevents font size adjustments after device orientation changes.
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
/* Document
========================================================================== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
html {
line-height: 1.15; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
}
Section and Article Styles
Removes default margins from the body and ensures the 'main' element is displayed consistently across browsers.
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers.
*/
body {
margin: 0;
}
/**
* Render the 'main' element consistently in IE.
*/
main {
display: block;
}
Text-Level Semantics
Adjusts box sizing and border color inheritance in Firefox for elements like <hr>.
/* Grouping content
========================================================================== */
/**
* Add the correct box sizing in Firefox.
* Correct the inheritance of border color in Firefox. (Bug 688556)
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
Other packages similar to normalize.css
reset-css
Similar to normalize.css, reset-css is an npm package that provides CSS reset styles. It differs in that it aims to strip all default browser styling on elements, whereas normalize.css aims to make these styles consistent across browsers without removing as much of the default styling.
sanitize.css
sanitize.css is another CSS normalization library that not only normalizes styles but also corrects bugs and common browser inconsistencies. It is similar to normalize.css but includes more opinionated defaults that enforce better usability.
normalize.css
A modern alternative to CSS resets
NPM
npm install --save normalize.css
Bower
bower install --save normalize-css
CDN
See https://cdnjs.com/libraries/normalize
Download
See https://necolas.github.io/normalize.css/latest/normalize.css
What does it do?
- Preserves useful defaults, unlike many CSS resets.
- Normalizes styles for a wide range of elements.
- Corrects bugs and common browser inconsistencies.
- Improves usability with subtle modifications.
- Explains what code does using detailed comments.
Browser support
- Chrome (last two)
- Edge (last two)
- Firefox (last two)
- Firefox ESR
- Internet Explorer 8+
- Opera (last two)
- Safari 6+
[Normalize.css v1 provides legacy browser support]
(https://github.com/necolas/normalize.css/tree/v1) (IE 6+, Safari 4+),
but is no longer actively developed.
Extended details and known issues
Additional detail and explanation of the esoteric parts of normalize.css.
pre, code, kbd, samp
The font-family: monospace, monospace
hack fixes the inheritance and scaling
of font-size for preformatted text. The duplication of monospace
is
intentional. Source.
sub, sup
Normally, using sub
or sup
affects the line-box height of text in all
browsers. Source.
svg:not(:root)
Adding overflow: hidden
fixes IE9's SVG rendering. Earlier versions of IE
don't support SVG, so we can safely use the :not()
and :root
selectors that
modern browsers use in the default UA stylesheets to apply this style. [Source]
(https://lists.w3.org/Archives/Public/public-svg-wg/2008JulSep/0339.html).
select
By default, Chrome on OS X and Safari on OS X allow very limited styling of
select
, unless a border property is set. The default font weight on optgroup
elements cannot safely be changed in Chrome on OSX and Safari on OS X.
[type="checkbox"]
It is recommended that you do not style checkbox and radio inputs as Firefox's
implementation does not respect box-sizing, padding, or width.
[type="number"]
Certain font size values applied to number inputs cause the cursor style of the
decrement button to change from default
to text
.
[type="search"]
The search input is not fully stylable by default. In Chrome and Safari on
OSX/iOS you can't control font
, padding
, border
, or background
. In
Chrome and Safari on Windows you can't control border
properly. It will apply
border-width
but will only show a border color (which cannot be controlled)
for the outer 1px of that border. Applying -webkit-appearance: textfield
addresses these issues without removing the benefits of search inputs (e.g.
showing past searches). Safari (but not Chrome) will clip the cancel button on
when it has padding (and textfield
appearance).
::placeholder
In Edge, placeholders will disappear on relative
or absolute
positioned
<input>
elements if you use opacity
less than 1
due to a bug.
Contributing
Please read the contribution guidelines in order to make the
contribution process easy and effective for everyone involved.
Acknowledgements
Normalize.css is a project by Nicolas Gallagher,
co-created with Jonathan Neal.